package com.yanglei.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.yanglei.service.HystrixOrderService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class HystrixOrderController {
    @Resource
    private HystrixOrderService hystrixOrderService;


    /**
     * 正常访问
     *
     * @param id
     * @return
     */
    @GetMapping("/consumer/payment/hystrix/ok/{id}")
    public String paymentInfo_ok(@PathVariable("id") String id) {
        String result = hystrixOrderService.paymentInfo_ok(id);
        return result;
    }

    /**
     * 超时
     *
     * @param id
     * @return
     */
    @GetMapping("/consumer/payment/hystrix/timeout/{id}")
    @HystrixCommand(fallbackMethod = "fallbackMethod", commandProperties = {
            @HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds", value = "15000")
    })
    public String paymentInfo_timeout(@PathVariable("id") String id) throws InterruptedException {
        int i = 10/0;
        String result = hystrixOrderService.paymentInfo_No(id);
        return result;
    }

    public String fallbackMethod(String id){
        return "我是服务端8080808080888888888888888888880000000000000000000000， 服务降级服务降级服务降级服务降级服务降级服务降级服务降级服务降级服务降级服务降级服务降级服务降级服务降级服务降级服务降级服务降级";
    }
}
